package com.base.cn.platform.os.controller.op.groom;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.utils.DataUtil;
import com.base.cn.platform.os.common.utils.ObjectUtils;
import com.base.cn.platform.os.common.utils.StringUtils;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.op.groom.OpGroomPlace;
import com.base.cn.platform.os.service.op.groom.OpGroomPlaceBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 推荐位置Controller
 *
 * @author ll
 * @create 2018-05-07
 */
@RestController
@RequestMapping("/manage/op")
public class OpGroomPlaceController extends BaseController {

    @Autowired
    private OpGroomPlaceBiz opGroomPlaceBiz;

    /**
     * 添加修改推荐位置
     * @param groomPlace
     * @return
     */
    @RequestMapping("/ajaxSaveUpdateGroomPlace")
    public Map<String,Object> ajaxSaveUpdateGroomPlace(@RequestBody OpGroomPlace groomPlace){
        if(!ObjectUtils.isNotEmpty(groomPlace)){
            return ResultUtil.ERROR("操作数据不能为空");
        }
        if(StringUtils.isEmpty(groomPlace.getPlaceName())){
            return ResultUtil.ERROR("请添写名称");
        }
        if(!ObjectUtils.isNotEmpty(groomPlace.getDepict())){
            return ResultUtil.ERROR("请填写推荐量");
        }
        OpGroomPlace opGroomPlace =opGroomPlaceBiz.saveUpdateGroomPlace(groomPlace);
        if (ObjectUtils.isNotEmpty(opGroomPlace)){
            if(DataUtil.idIsNotNull(groomPlace.getId())){
                return ResultUtil.SUCCESS("修改成功",opGroomPlace);
            }else{
                return ResultUtil.SUCCESS("添加成功",opGroomPlace);
            }
        }
        return ResultUtil.ERROR("系统繁忙请稍后再试");
    }


    /**
     * 搜索ajax列表
     * @param groomPlace
     * @return
     */
    @RequestMapping("/queryAjaxGroomPlaceListPage")
    public PageInfo<OpGroomPlace> queryAjaxGroomPlaceListPage(@RequestParam(value = "currentPage",required = false,defaultValue = "1")Integer currentPage,
                                          @RequestBody OpGroomPlace groomPlace){
        Pagination page = new Pagination();
        page.setCurrentPage(currentPage);
        page.setPageSize(20);
        PageInfo<OpGroomPlace> groomPlaces = opGroomPlaceBiz.queryGroomPlaceListPage(page,groomPlace);
        return groomPlaces;
    }

    /**
     * 冻结，恢复
     * @param groomPlaceIds
     * @param status
     * @return
     */
    @RequestMapping("/updateGroomPlaceStatusByIds")
    public Map<String,Object> updateGroomPlaceStatusByIds(@RequestParam("groomPlaceIds")String groomPlaceIds,
                                                          @RequestParam("status")Integer status){
        opGroomPlaceBiz.updateGroomPlaceStatusByIds(groomPlaceIds, status);
        String message ="";
        if (status == 1){
            message = "恢复成功";
        }else if (status == 2){
            message = "冻结成功";
        }else if (status == 3){
            message = "删除成功";
        }
        return ResultUtil.SUCCESS(message);
    }

    /**
     * 查看，修改推荐位置,
     * @param id
     * @return
     */
    @RequestMapping("/groomPlaceInfo")
    public OpGroomPlace groomPlaceInfo(@RequestParam("id")BigDecimal id){
        return opGroomPlaceBiz.queryGroomPlaceInfo(id,true);
    }

    /**
     * 根据Id 查询推荐位置
     */
    @RequestMapping("/groomPlaceById")
    public OpGroomPlace groomPlaceById(@RequestParam("id")BigDecimal id){
        return opGroomPlaceBiz.queryGroomPlaceInfo(id,false);
    }

    /**
     * 后台批量推荐
     * @param dataType 类型
     * @param status 状态
     * @param isDataType  false 不搜索dataType null
     * @return
     */
    @RequestMapping("/queryOpGroomPlaceByDataType")
    public List<OpGroomPlace> queryOpGroomPlaceByDataType(@RequestParam("dataType")String dataType,
                                                          @RequestParam(value = "status",required = false,defaultValue = "1")Integer status,
                                                          @RequestParam(value = "isDataType",required = false,defaultValue = "false")boolean isDataType){
        return opGroomPlaceBiz.queryOpGroomPlaceByDataType(dataType,status,isDataType);
    }
}
